package cn.com.w.jdk.thread.pool.controller;

import cn.com.w.common.thread.bean.ListTestData;
import cn.com.w.common.thread.worker.SendDataWorker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Executor;

@Component
@DependsOn(value = {"jdkExector"})
public class SendDataController {

    Logger logger = LoggerFactory.getLogger(SendDataController.class);

    @Resource(name = "jdkExector")
    Executor executor;

    public void sendData() {

        List<String> stringList = ListTestData.getTestData();

        Iterator<String> iterator = stringList.iterator();
        while (iterator.hasNext()) {
            String str = iterator.next();
            // jdk线程池
            executor.execute(new SendDataWorker(str));
            int maximumPoolSize =  Runtime.getRuntime().availableProcessors();
            logger.info("服务器可使用进程数量：[{}]", maximumPoolSize);

        }
    }

}